<%@ page contentType="text/html; charset=utf-8" language="java" import="java.util.*" pageEncoding="utf-8" errorPage="" %>
<%@ page import="club325.webchat.servlet.log.SessionAttributeManager" %>
<%@ page import="club325.webchat.servlet.log.UserAttribute" %>
<%@ page session="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/main.dwt.jsp" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>聊天室</title>
<!-- InstanceEndEditable -->

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Keywords" content="WebChat,Chat" />
<meta http-equiv="Description" content="Chatting on Web" />
<!-- InstanceBeginEditable name="head" -->
<link href="/WebChat/style/chat_room.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="/WebChat/lib/util.js"></script>
<script type="text/javascript">
<!--
	function createRoom(){
		var roomname = document.getElementById("roomname").value;
		var re = new RegExp("^[A-Za-z0-9]+$"); 
		if (roomname == '') {
			document.getElementById("tip").innerHTML = '提示 : 聊天室名不能为空！';
			return;
		} else if (roomname.length < 5) {
			document.getElementById("tip").innerHTML = '提示 : 聊天室名过短！';
			return;
		} else if (roomname.length > 10) {
			document.getElementById("tip").innerHTML = '提示 : 聊天室名过长！';
			return;
		} else if (!re.test(roomname)) {
			document.getElementById("tip").innerHTML = '提示 : 聊天室名非法！';
			return;
		} else {
			document.getElementById("tip").innerHTML = '提示 : 正在创建的聊天室...';
			openBareWindow('_blank', '/WebChat/servlet/CreateRoomChatServlet?subject=' + roomname, 650, 500);
			document.getElementById("roomname").value = '';
			document.getElementById("tip").innerHTML = '提示 : 请输入所要创建的聊天室名...';
			setTimeout(refreshRoomList, 5000); 		
			return;
		}
	}
	
	function refreshRoomList(){
		chat_roomlist.location.reload();
		chat_roomcheck.location.href = '/WebChat/lib/chat_roomcheck.jsp';
	}
//-->
</script>
<!-- InstanceEndEditable -->

<link href="/WebChat/style/global.css" rel="stylesheet" type="text/css" />
<link href="/WebChat/style/template.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="top">
  <div id="top_main">
    <ul>
      <li><a href="#">设为首页</a>|</li>
      <li><a href="#">会员注册</a>|</li>
      <li><a href="#">用户登录</a>|</li>
      <li><a href="#">联系我们</a></li>
    </ul>
  </div>
</div>

<div id="main">
  <div id="head">
    <div id="head_main"><img src="/WebChat/images/logo.png" width="200" height="70" alt="logo" />
    <%
    	HttpSession session = request.getSession(false);
    	UserAttribute userAttribute = null;
    	String username = null;
    	String userrole = null;
    	boolean isUser = false;
    	boolean isAdmin = false;
    	if (session != null) {
    		userAttribute = (UserAttribute)session.getAttribute(SessionAttributeManager.SESSION_USERATTRIBUTE);
    		if (userAttribute != null) {
    			username = userAttribute.getUserName();
    			userrole = userAttribute.getUserRole();
    		}
    	}
    	if (username != null && userrole != null) {
    		if (userrole.equals(UserAttribute.USERROLE_ADMIN)) {
    			isUser = true;
    			isAdmin = true;
    		} else if (userrole.equals(UserAttribute.USERROLE_USER)) {
    			isUser = true;
    			isAdmin = false;
    		} else {
    			isUser = false;
    			isAdmin = false;
    		}
    %>
      <div id="head_main_info">
        <h1 class="<%= userrole %>"><%= username %></h1>
        <ul>
        <%
        	if (isUser) {
        %>
          <li><a href="/WebChat/pages/user_frame.jsp">个人中心</a>|</li>
        <%
        	}
        %>
          <li><a href="/WebChat/servlet/LogoutServlet">退出</a></li>
        </ul>
      </div>
    <%
    	}
    %>
    </div>
    <div id="head_nav">
      <ul>
        <li><a href="/WebChat/index.jsp">首 页</a></li>
        <li><a href="/WebChat/pages/chat_random.jsp">随机聊天</a></li>
        <li><a href="/WebChat/pages/chat_room.jsp">聊天室</a></li>
        <li><a href="/WebChat/servlet/HallChatServlet">聊天大厅</a></li>
        <%
        	if (isAdmin) {
      	%>
        <li><a href="/WebChat/pages/admin_frame.jsp">管理中心</a></li>
        <%
        	}
      	%>
      </ul>
      <%
        	if (isUser) {
      %>
      <p><a href="/WebChat/pages/user_frame.jsp"><img src="/WebChat/images/arrow_next.png" width="18" height="16" alt="arrow_next" />进入会员中心</a></p>
      <%
        	}
      %>
    </div>
  </div>
  <!-- InstanceBeginEditable name="EditRegion_body" -->
  <div id="body">
    <div id="body_left">
      <div id="body_left_room">
        <h1>聊天室列表</h1>
        <div id="body_left_room_list">
          <iframe id="chat_roomlist" name="chat_roomlist" src="/WebChat/lib/chat_roomlist.jsp" width="270" height="390" frameborder="0"></iframe>
        </div>
      </div>
      <div id="body_left_user">
        <h1>聊天室详细信息</h1>
        <div id="body_left_user_check">
          <iframe id="chat_roomcheck" name="chat_roomcheck" src="/WebChat/lib/chat_roomcheck.jsp" width="250" height="330" frameborder="0"></iframe>
        </div>
      </div>
      <div id="body_left_refresh">
        <form id="form_refresh" name="form_refresh" method="post" action="#">
          <input type="button" name="refresh" id="refresh" value="" onclick="refreshRoomList();"/>
        </form>
      </div>
    </div>
    <div id="body_right">
      <div id="body_right_create">
        <h1>创建聊天室</h1>
        <div id="body_right_create_name">
          <form id="form_create" name="form_create" method="post" action="#" onsubmit="createRoom(); return false;">
            <h2>请输入所要创建的聊天室名(请以5~10位的数字和字母组合命名) : </h2>
            <input type="text" name="roomname" id="roomname" value="" />
            <h3 id="tip">提示 : 请输入所要创建的聊天室名...</h3>
            <input type="submit" name="submit" id="submit" value="" />
            <input type="reset" name="reset" id="reset" value="" />
          </form>
        </div>
      </div>
      <div id="body_right_leave">
        <form id="form_leave" name="form_leave" method="post" action="#">
          <input type="button" name="leave" id="leave" value="" onclick="self.close();"/>
        </form>
      </div>
    </div>
  </div>
  <!-- InstanceEndEditable -->
</div>

<div id="bottom">
  <p>Copyright © 2009 - 2010 CLUB325.  All Rights Reserved<br/>
  CLUB325  版权所有</p>
</div>
</body>
<!-- InstanceEnd --></html>
